package com.emotion.recognition.server.mlp;

import java.util.List;

import com.google.gwt.dev.util.Preconditions;
import com.google.gwt.thirdparty.guava.common.collect.Lists;

public class InputLayer extends AbstractLayer<InputNode> {

    List<InputNode> nodes;

    public static InputLayer create(int numInputs, Double bias) {
        return new InputLayer(numInputs, bias);
    }

    private InputLayer(int numInputs, Double bias) {
        super("Input Layer", bias);

        Preconditions.checkArgument(numInputs > 0, "Must have at least one input dimension");

        nodes = Lists.newArrayList();
        for (int i = 0; i < numInputs; i++) {
            add(InputNode.create());
        }
    }

    /**
     * Provide this layer with a list of input values, such that the outputs from this layer is
     * propagated to the next layer, which in turn propagates to the next one, eventually reaching
     * the output layer.
     */
    public void provideInputToAll(List<Double> input) {
        Preconditions.checkArgument(input.size() == nodes.size(),
                "Input dimension and number of input nodes do not match");

        for (int i = 0; i < input.size(); i++) {
            get(i).provideInput(input.get(i));
        }
    }

    @Override
    protected List<InputNode> getList() {
        return nodes;
    }
}
